package tt.dz.order.util.refund;

import java.math.BigDecimal;

import org.apache.commons.lang.StringUtils;

import tt.dz.order.pojo.AliPayCallBackRecord;
import tt.dz.order.pojo.OrderInfo;
import tt.dz.order.pojo.OrderServiceInfo;

/**
 * 
 * 
 * @name 退款业务的公共方法抽取
 * @author Anson
 * @version 1.0
 * @summary
 * @desc
 *
 */
public abstract class AbstractRefundingRequest implements RefundingRequest {

	protected OrderInfo refundOrder;

	protected OrderInfo payRecordRelateOrder;

	protected String reason;

	@Override
	public void setOrderInfo(OrderInfo refundOrder) {
		this.refundOrder = refundOrder;
	}

	@Override
	public void setPayRecordRelateOrder(OrderInfo payRecordRelateOrder) {
		this.payRecordRelateOrder = payRecordRelateOrder;
	}

	@Override
	public void setRefundReason(String reason) {
		this.reason = reason;
	}
	/**
	 * 根据订单号，获取ali支付记录
	 * 
	 * @param orderNo
	 * @return
	 */
	protected AliPayCallBackRecord aliPayCallBackRecord(String orderNo) {
		return StringUtils.isEmpty(orderNo) ? null : AliPayCallBackRecord.getBy(orderNo);
	}

	/**
	 * 根据订单查询当前主服务信息
	 * 
	 * @param order
	 * @return
	 */
	protected OrderServiceInfo mainServiceInfo(OrderInfo order) {
		if (order == null) {
			return null;
		}
		String serviceNo = order.getServiceNo();
		if (StringUtils.isEmpty(serviceNo)) {
			return null;
		}
		return OrderServiceInfo.getById(serviceNo);
	}

	/**
	 * 处理金额
	 * 
	 * @param money
	 * @return
	 */
	protected String accRefundMoney(BigDecimal money) {
		return money.abs().toString();
	}
}
